package wiki.xsx.jg.core;

import java.util.*;

/**
 * 实体类对象，可看作数据库中对应的表或数据表对应的Java类
 */
public class Entity {
    // 名称
    private String name;
    // 字段对象集合
    private Map<String, Field> fieldMap = new LinkedHashMap<>();
    // 注释
    private String comment;

    public Entity(String name, String comment) {
        this.name = name;
        this.comment = comment;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<String, Field> getFieldMap() {
        return fieldMap;
    }

    public Set<Field> getColumnSet() {
        return new LinkedHashSet<>(fieldMap.values());
    }

    public Field getColumn(String columnName) {
        return fieldMap.get(columnName);
    }

    public void setFieldMap(Map<String, Field> fieldMap) {
        this.fieldMap = fieldMap;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public String toString() {
        return "Entity{" +
                "name='" + name + '\'' +
                ", fieldMap=" + fieldMap +
                ", comment='" + comment + '\'' +
                '}';
    }
}
